package com.test.client.handler;

import com.test.client.TcpClient;
import com.test.constant.FunCodeConstant;
import com.test.message.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TcpClientHandler extends SimpleChannelInboundHandler<Object> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        Message messagefrom = (Message) msg;
//		System.out.println("client received:"+msg);
        log.info("messagefrom{}", messagefrom);
        Thread.sleep(7000);    //延时9秒
//        LoginResponseMessage loginResponseMessage = new LoginResponseMessage();
//        loginResponseMessage.setIemi("222222222");
//        byte[] bytes = JSON.toJSONBytes(loginResponseMessage);
        Message message = new Message();
        message.setHead((short) 0xBB);
        message.setFunCode(FunCodeConstant.LOGIN_CODE.byteValue());
        byte[] bytes = new byte[0];
        message.setMessageData(bytes);
        message.setMessageLength((short) bytes.length);
        log.info("ooooooooooooooooo{}", message);
        TcpClient.sendMsg(message);
    }

}
